local gengji = fk.CreateSkill{
  name = "xiaobai__gengji",
}

Fk:loadTranslationTable{
  ["xiaobai__gengji"] = "耕积",
  [":xiaobai__gengji"] = "你可以将一张非基本牌置于牌堆底并跳过判定阶段，若如此做，结束阶段，你视为使用【五谷丰登】，"..
    "且此牌仅指定有“耕积”的角色为目标。",
  ["#xiaobai__gengji"] = "耕积：你可以将一张非基本牌置于牌堆底并跳过判定阶段",
  ["@@xiaobai__gengji-turn"] = "耕积",
}

gengji:addEffect(fk.EventPhaseChanging, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return data.phase == Player.Judge and player:hasSkill(gengji.name) and target == player
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      pattern = ".|.|.|.|.|^(basic)",
      skill_name = gengji.name,
      prompt = "#xiaobai__gengji",
      cancelable = true,
      include_equip = true,
    })
    if #cards > 0 then
      event:setCostData(self, {card = cards[1]})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local card = event:getCostData(self).card
    room:moveCards{
      ids = {card},
      drawPilePosition = -1,
      moveReason = fk.ReasonPut,
      from = player,
      moveVisible = true,
      proposer = player,
      toArea = Card.DrawPile 
    }
    room:addPlayerMark(player, "@@xiaobai__gengji-turn", 1)
    data.skipped = true
  end,
})

gengji:addEffect(fk.EventPhaseStart, {
  anim_type = "support",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return player:getMark("@@xiaobai__gengji-turn") > 0 and target == player and data.phase == Player.Finish
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("amazing_grace")
    card.skillName = gengji.name
    local targets = table.filter(room:getAlivePlayers(), function (t)
      return t:hasSkill(gengji.name)
    end)
    room:useCard{
      card = card,
      tos = targets,
      from = player
    }
  end
})

return gengji